<!DOCTYPE html>
{% load staticfiles %}
<html lang="en" manifest="{% static 'manifest.appcache' %}">
<head>
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title>{% block base_title %} 框架首页 {% endblock %}</title>
    {% block link_script%} {% endblock%}
    <link rel="stylesheet" href="{% static 'css/semantic.min.css' %}">
    <!--<link rel="stylesheet" href="{% static 'css/swiper-3.4.2.min.css' %}">-->
    <link rel="stylesheet" href="{% static 'css/vonic.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/css.css' %}">
    <!--<link rel="stylesheet" href="{% static '' %}">-->
    <script src="{% static 'js/axios.min.js' %}"></script>
    <script src="{% static 'js/vue.min.js' %}"></script>
    <!--<script src="{% static 'js/vue-router.min.js' %}"></script>-->
    <script src="{% static 'js/jquery.min.js' %}"></script>
    <script src="{% static 'js/public.js' %}"></script>
    <script src="{% static 'js/reqwest.js' %}"></script>
    <!--<script src="{% static 'js/swiper-3.4.2.min.js' %}"></script>-->

</head>
<body>

<div id="login"></div>

{% block base_body %} {% endblock %}
</body>
<script>
    {% block base_script %} {% endblock %}
    new Vue({
        el:'#login',
        loading: 0,
        methods:{
           login:function(){
               var ur=window.location.href.split("?").pop();
               // localStorage.clear();
               //console.log(ur);
               if(ur!=''&&ur.indexOf('phone')!=-1) {
                   var phone = localStorage.getItem('phone');
                   var pass = localStorage.getItem('pass');
                   var token = localStorage.getItem('token');
                   var uid = localStorage.getItem('uid');
                   if(phone==ur.split('&')[0].split('=')[1]&&pass==ur.split('&')[1].split('=')[1] && token!=null&&uid!=null&&token!=''&&uid!=''&& token!="undefined"&&uid!="undefined") {
                       this.run();
                       this.update();
                   }else {
                       localStorage.clear();
                       window.localStorage.setItem('phone', ur.split('&')[0].split('=')[1]);
                       window.localStorage.setItem('pass', ur.split('&')[1].split('=')[1]);
                       var self=this;
                       reqwest({
                           url: 'http://api.zgtxcj.com/straapi/login/',
                           method: 'post',
                           type: 'json',
                           data: {
                               username: localStorage.getItem('phone'),
                               passwd: localStorage.getItem('pass'),
                               tag: 'xz'
                           },
                           success: function (resp) {
                               if (resp != false) {
                                   window.localStorage.setItem('token', resp['TOKEN']);
                                   window.localStorage.setItem('uid', resp['U_ID']);
                                   self.run();
                               }
                           }
                       })
                   }
               }
           },
           manifest_update:function(){
                if (window.applicationCache.status == window.applicationCache.UPDATEREADY){
                    window.applicationCache.update();
                }
           },
            update:function () {
                var token = localStorage.getItem('token');
                var uid = localStorage.getItem('uid');
                reqwest({
                    url: 'http://api.zgtxcj.com/straapi/login/',
                    method: 'get',
                    type: 'json',
                    data: {
                        username: localStorage.getItem('phone'),
                        token: localStorage.getItem('token'),
                        tag: 'xz'
                    },
                    success: function (resp) {
                        if (resp != false && resp != true) {
                            window.localStorage.setItem('token', resp);
                        }else {
                            reqwest({
                                url: 'http://api.zgtxcj.com/straapi/login/',
                                method: 'post',
                                type: 'json',
                                data: {
                                    username: localStorage.getItem('phone'),
                                    passwd: localStorage.getItem('pass'),
                                    tag: 'xz'
                                },
                                success: function (resp) {
                                    if (resp != false) {
                                        window.localStorage.setItem('token', resp['TOKEN']);
                                        window.localStorage.setItem('uid', resp['U_ID']);
                                    }
                                }
                            })
                        }
                    }
                })

            },
            run: function () {
                {% block base_run %}{% endblock %}.run()
            }

        },
        beforeMount:function(){
            this.manifest_update();
            this.login();
        },
    });
</script>
</html>